package com.bobo;

/**
 * @Author: bobobo
 * @Date: 2019/9/5 20:36
 * @Version：1.0
 */
public class ThreeGateExperiment {
    private int N;

    public ThreeGateExperiment(int N){
        if (N < 0)
            throw new IllegalArgumentException("N must larger than 0");

        this.N = N;
    }

    public void run(boolean changeDoor){
        int Wins = 0;
        for (int i = 0;i < N;i++)
            if (play(changeDoor))
                Wins++;

        System.out.println(changeDoor ? "选择换门" : "选择不换门");
        System.out.println("胜率是" + (double)Wins / N);
    }

    private boolean play(boolean changeDoor){
        // Door 0 1 2
        int prizeDoor = (int) (Math.random() * 3);
        int playChoice = (int) (Math.random() * 3);

        if (playChoice == prizeDoor)
            return changeDoor ? false : true;
        else
            return changeDoor ? true : false;
    }

    public static void main(String[] args) {
        int N = 100000;

        ThreeGateExperiment experiment = new ThreeGateExperiment(N);
        experiment.run(true);
        experiment.run(false);
    }
}
